'''
Created on 2013-6-25

@author: ZuoPeng
'''

class P87(object):
    '''
    classdocs
    '''


    def __init__(self,max_num):
        '''
        Constructor
        '''
        self.max=max_num
        self.max_square=int(self.max**0.5)+1
        self.max_cube=int(self.max**(1/3))+1
        self.max_4power=int(self.max**0.25)+1
        
        self.prime=list(range(2,self.max_square+1))
        for i in self.prime:
            for j in self.prime:
                if j>i and j%i==0:
                    self.prime.remove(j)
                        
        
        
    def calc(self):
        l=[]
        p2=p3=p4=0
        for p2 in self.prime:
            print(p2)
            if p2**2+2**3+2**4>self.max:
                print(p2)
                print(p3)
                print(p4)
                break
            for p3 in self.prime:
                if p2**2+p3**3+16>self.max:
                    break
                for p4 in self.prime:
                    v=p2**2+p3**3+p4**4
                    if v>self.max:
                        break
                    else:
                        l.append(v)
        l=set(l)
        print(len(l))

p=P87(50000000)
p.calc()        